package cn.wolfcode.business.controller;


import cn.wolfcode.business.domain.BusAppointment;
import cn.wolfcode.business.domain.BusServiceItem;
import cn.wolfcode.business.domain.BusStatement;
import cn.wolfcode.business.service.BusStatementService;
import cn.wolfcode.common.core.controller.BaseController;
import cn.wolfcode.common.core.domain.AjaxResult;
import cn.wolfcode.common.core.page.TableDataInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/business/statement")
//手写的controller需要继承BaseController
public class BusStatementController extends BaseController {
    @Autowired
    BusStatementService busStatementService;

    /**
     * 获取结算单列表
     * 对于前端传递的
     *
     * @param busStatement
     * @return
     */
    @GetMapping("/list")
    public TableDataInfo getList(BusStatement busStatement) {
        startPage();
        System.out.println("busStatement.getIsDelete() = " + busStatement.getIsDelete());
        List<BusServiceItem> list = busStatementService.getList(busStatement);
        return getDataTable(list);
    }

    /**
     * 查询一条结算单记录
     *
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public AjaxResult getStatement(@PathVariable() Long id) {
        return AjaxResult.success(busStatementService.getStatement(id));
    }

    /**
     * 新增结算单信息
     */
    @PostMapping
    public AjaxResult add(@RequestBody BusStatement busStatement) {
        return AjaxResult.success(busStatementService.add(busStatement));
    }

    /**
     * 生成结算单
     */
    @PostMapping("/{id}")
    public AjaxResult generateStatement(@RequestBody BusAppointment busAppointment) {
        return AjaxResult.success(busStatementService.generateStatement(busAppointment));
    }

    /**
     * 编辑结算单
     */
    @PutMapping
    public AjaxResult update(@RequestBody BusStatement busStatement) {
        return AjaxResult.success(busStatementService.update(busStatement));
    }

    /**
     * 删除功能  --软删除 只修改一个 isDelete //0没有删除/1删除
     */
    @PatchMapping(value = "/{id}", headers = "cmd=delete")
    public AjaxResult delete(@PathVariable("id") Long id) {
        return AjaxResult.success(busStatementService.delete(id));
    }

}
